/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
*/

package com.jinhe.tss.component.log;

import java.util.List;

import com.jinhe.tss.component.param.extend.ParamConfig;
import com.jinhe.tss.core.cachepool.CacheManager;
import com.jinhe.tss.core.cachepool.Cacheable;
import com.jinhe.tss.core.cachepool.IPool;
import com.jinhe.tss.core.cachepool.extend.assignment.OutputRecordsManager;
import com.jinhe.tss.core.cachepool.strategy.CacheConstants;

/**
 * <p>  BusinessLogger.java  </p>
 * 
 * 跟业务操作相关的日志记录器
 * 
 */
public class BusinessLogger extends OutputRecordsManager implements IBusinessLogger{
   
    private IPool apool;
 
    public BusinessLogger(){
        apool = CacheManager.getInstance().getCachePool(CacheConstants.ASSIMENT_POOL);
    }

    protected void excuteTask(List<Object> temp) {
        Cacheable item = apool.checkOut(0);
        LogOutputTask task = (LogOutputTask) item.getValue();
        task.fill(temp);
        item.update(task);
        
        log.debug("正在执行业务日志输出，本次共记录【" + temp.size() +  "】条日志。");
        tpool.excute(apool, item);
    }

    public void output(LogDto dto) {
        super.output(dto);
    }
    
    protected int getMaxSize(){
        try{
            return Integer.parseInt(ParamConfig.getAttribute(LogConstants.LOG_FLUSH_MAX_SIZE_NAME));
        }catch(Exception e){
            return super.getMaxSize(); 
        }
    }
}
